/**
 * @Description:  message
 * @author longfa liang
 * @date 2021/9/1
 */

var redis = require('../db/redis')
var pu = require('../tool/public')
var mg = require('../db/userdb')


class message {

    async sendmsg (userlist, msg) {
        for (var i = 0; i < userlist.length; i++) {
            await redis.hset('USER_NOTICE_' + userlist[i].toString(), pu.uuid(), JSON.stringify(msg))
        }

    }

    async sendemail (userid, msg) {
        let info = await mg.find('team_user', { _id: mg.ObjectID(userid) })
        if (info.email) {
            pu.sendMail(info.email, JSON.stringify(msg))
        }
    }
}

module.exports = new message()
